public class Nucleotide
{

	private String nucleotide;
	private static String complementString;

	public Nucleotide(char first, char second)
	{
		nucleotide = new String();
		nucleotide += first;
		nucleotide += second;
		// System.out.println(complementString.length());
		// complementString = new String();
	}

	public Nucleotide(Nucleotide d)
	{
		nucleotide = new String(d.getNucleotide());
	}

	public String getNucleotide()
	{
		return nucleotide;
	}

	public static void clearComplementaritySet()
	{
		complementString = new String();
	}

	public static void addComplementaritySet(char a, char b)
	{
		complementString += a;
		complementString += b;
	}

	public static void addComplementaritySet(String a)
	{
		complementString = new String(a);
	}

	public char getFirst()
	{
		return getNucleotide().charAt(0);
	}

	public char getSecond()
	{
		return getNucleotide().charAt(1);
	}

	// Operateur de comparaison.
	// return > 0 pour vrai et < 0 pour faux, sinon 0 pour l egalite.
	public short isGreaterThan(Nucleotide d)
	{
		/*
		 * display(); System.out.print(" isgreater than " ); d.display();
		 */
		short result = 0;
		if (getFirst() > d.getFirst())
			result += 2;
		else if (getFirst() < d.getFirst())
			result += -2;
		else
		{
			if (getSecond() > d.getSecond())
				result += 1;
			else if (getSecond() < d.getSecond())
				result += -1;
		}
		/*
		 * System.out.print("--" + result + "--"); System.out.println();
		 */
		return result;
	}

	private char _complementarity(char c)
	{

		for (int i = 0; i < complementString.length(); i += 2)
		{
			if (complementString.charAt(i) == c)
			{
				return complementString.charAt(i + 1);
			}
		}
		return c;
	}

	public Nucleotide complementarity()
	{
		return new Nucleotide(_complementarity(getSecond()),
				_complementarity(getFirst()));
	}

	public Nucleotide permute()
	{
		return new Nucleotide(getSecond(), getFirst());
	}

	public void display()
	{
		System.out.print(getFirst());
		System.out.print(getSecond());
	}

}
